/**
 * 
 */
package jpb.test.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import jpb.JavaProcessBuilder;

/**
 * Utilities for easy testing of Java application arguments API of the
 * {@link JavaProcessBuilder}.
 * 
 * @author Dariusz Kordonski
 */
public final class ArgumentTestUtils {

    private static final Random RANDOM = new Random();
    
    private ArgumentTestUtils() {
        throw new AssertionError();
    }
    
    public static String[] randomArgumentArray() {
        String[] answer = new String[RANDOM.nextInt(10)+1];
        for (int i = 0; i < answer.length; i++) {
            answer[i] = Integer.toHexString(RANDOM.nextInt());
        }
        return answer;
    }
    

    public static String[] repeat(String[] args, int repeatCount) {
        return repeatAsList(args, repeatCount).toArray(new String[args.length*repeatCount]);
    }
    
    
    public static List<String> repeatAsList(String[] args, int repeatCount) {
        List<String> fixtureAsList = Arrays.asList(args);
        List<String> answer = new ArrayList<String>(fixtureAsList.size()*repeatCount);
        for (int i = 0; i < repeatCount; i++) {
            answer.addAll(fixtureAsList);
        }
        return answer;
    }

}
